﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.IO;

namespace SWCInvoice.Windows
{
    /// <summary>
    /// Interaction logic for Help.xaml
    /// </summary>
    public partial class Help : UserControl
    {
        const string BASE_HELP_PATH = @"\Help\HTML\"; 

        public Help()
        {
            InitializeComponent();

            /*
            // Handle DocumentCompleted to gain access to the Document object.
            helpWebBrowser.DocumentCompleted +=
                new WebBrowserDocumentCompletedEventHandler(
                    helpWebBrowser_DocumentCompleted);
            */
           
            helpWebBrowser.AllowNavigation = true;

            /*helpWebBrowser.ScriptErrorsSuppressed = false;*/
            helpWebBrowser.ScriptErrorsSuppressed = true;

            SetPage("SWCInvoice Help.html");
          
        }

        public Help(string file) {
            InitializeComponent();

            helpWebBrowser.AllowNavigation = true;

            helpWebBrowser.ScriptErrorsSuppressed = true;

            SetPage(file);
        }

        /// <summary>
        /// Set the page in the Browsercontrol
        /// </summary>
        /// <param name="file">the html file without the base path</param>
        private void SetPage(string file){

            Uri uri = new Uri(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + BASE_HELP_PATH + file, UriKind.RelativeOrAbsolute);

            this.helpWebBrowser.Navigate(uri);
        
        }

        /*
        private void helpWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            ((System.Windows.Forms.WebBrowser)sender).Document.Window.Error +=
                new HtmlElementErrorEventHandler(Window_Error);
        }

        private void Window_Error(object sender,
            HtmlElementErrorEventArgs e)
        {
            // Ignore the error and suppress the error dialog box. 
            e.Handled = true;
        }
        */
    }
}
